import os
from utils import read_config as config
from webs.service import config_service

users_path = os.path.join(config.data_path, 'common', 'users')


# 获取当日触发情况
# flag 1:查询当前触发 2:查询全部触发
def get_login_html():
    a = b''
    a += b'<!DOCTYPE html>'
    a += b'<html lang="en">'
    a += b'<head>'
    a += b'    <meta charset="utf-8">'
    a += b'    <meta name="viewport" content="width=device-width, initial-scale=1">'
    a += b'    <meta name="keywords" content="">'
    a += b'    <meta name="description" content="">'
    a += b'    <meta name="author" content="">'
    a += b'    <link rel="icon" href="assets/images/favicon.png" type="image/png">'
    a += b'    <title></title>'
    a += b'    <link href="assets/css/icons.css" rel="stylesheet">'
    a += b'    <link href="assets/css/bootstrap.min.css" rel="stylesheet">'
    a += b'    <link href="assets/css/style.css" rel="stylesheet">'
    a += b'    <link href="assets/css/responsive.css" rel="stylesheet">'
    a += b'</head>'
    a += b'<body class="sticky-header">'
    a += b'<section class="login-section">'
    a += b'    <div class="container">'
    a += b'        <div class="row">'
    a += b'            <div class="login-wrapper">'
    a += b'                <div class="login-inner">'
    a += b'                    <div class="logo">'
    a += b'                        <img src="assets/images/logo-dark.png" alt="logo"/>'
    a += b'                    </div>'
    a += b'                    <h2 class="header-title text-center">Login</h2>'
    a += bytes('<form action="' + config_service.url3 + ' " method="post" name = "login" >', encoding='utf-8')
    a += b'                        <div class="form-group">'
    a += bytes(
        '<input type="text" class="form-control" placeholder="Username" name="' + config_service.username + '" >',
        encoding='utf-8')
    a += b'                        </div>'
    a += b'                        <div class="form-group">'
    a += bytes(
        '<input type="text" class="form-control" placeholder="Password" name="' + config_service.password + '" >',
        encoding='utf-8')
    a += b'                        </div>'
    a += b'                        <div class="form-group">'
    a += b'                            <div class="pull-left">'
    a += b'                                <div class="checkbox primary">'
    a += b'                                    <input id="checkbox-2" type="checkbox">'
    a += b'                                    <label for="checkbox-2">Remember me</label>'
    a += b'                                </div>'
    a += b'                            </div>'
    a += b'                            <div class="pull-right">'
    a += b'                                <a href="reset-password.html" class="a-link">'
    a += b'                                    <i class="fa fa-unlock-alt"></i> Forgot password?'
    a += b'                                </a>'
    a += b'                            </div>'
    a += b'                        </div>'
    a += b'                        <div class="form-group">'
    a += b'                            <input type="submit" value="Login" class="btn btn-primary btn-block">'
    a += b'                        </div>'
    a += b'                        <div class="form-group text-center">'
    a += bytes('未注册账户? <a href="registration.html">注册</a>', encoding='utf-8')
    a += b'                        </div>'
    a += b'                    </form>'
    a += b'                    <div class="copy-text">'
    a += b'                        <p class="m-0">2017 &copy; Meter admin</p>'
    a += b'                    </div>'
    a += b'                </div>'
    a += b'            </div>'
    a += b'        </div>'
    a += b'    </div>'
    a += b'</section>'
    a += b'<script src="assets/js/jquery.min.js"></script>'
    a += b'<script src="assets/js/bootstrap.min.js"></script>'
    a += b'</body>'
    a += b'</html>'
    return a


def login_check(params):
    username = params[config_service.username]
    if os.path.exists(os.path.join(users_path, username)):
        return 1
    return 0
